﻿using System;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using Catel.Data;

namespace Catel.Articles._03___MVVM.Models
{
    /// <summary>
    /// Bed Data object class which fully supports serialization, property changed notifications,
    /// backwards compatibility and error checking.
    /// </summary>
    [Serializable]
    public class Room : DataObjectBase<Room>
    {
        #region Constructor & destructor
        /// <summary>
        /// Initializes a new object from scratch.
        /// </summary>
        public Room()
            : this(NameProperty.GetDefaultValue<string>()) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="Room"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public Room(string name)
        {
            // Create collections
            Tables = new ObservableCollection<Table>();
            Beds = new ObservableCollection<Bed>();

            // Store values
            Name = name;
        }

        /// <summary>
        /// Initializes a new object based on <see cref="SerializationInfo"/>.
        /// </summary>
        /// <param name="info"><see cref="SerializationInfo"/> that contains the information.</param>
        /// <param name="context"><see cref="StreamingContext"/>.</param>
        protected Room(SerializationInfo info, StreamingContext context)
            : base(info, context) { }
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        public string Name
        {
            get { return GetValue<string>(NameProperty); }
            set { SetValue(NameProperty, value); }
        }

        /// <summary>
        /// Register the Name property so it is known in the class.
        /// </summary>
        public static readonly PropertyData NameProperty = RegisterProperty("Name", typeof(string), "Room");

        /// <summary>
        /// Gets or sets the table collection.
        /// </summary>
        public ObservableCollection<Table> Tables
        {
            get { return GetValue<ObservableCollection<Table>>(TablesProperty); }
            set { SetValue(TablesProperty, value); }
        }

        /// <summary>
        /// Register the Tables property so it is known in the class.
        /// </summary>
        public static readonly PropertyData TablesProperty = RegisterProperty("Tables", typeof(ObservableCollection<Table>));

        /// <summary>
        /// Gets or sets the bed collection.
        /// </summary>
        public ObservableCollection<Bed> Beds
        {
            get { return GetValue<ObservableCollection<Bed>>(BedsProperty); }
            set { SetValue(BedsProperty, value); }
        }

        /// <summary>
        /// Register the Beds property so it is known in the class.
        /// </summary>
        public static readonly PropertyData BedsProperty = RegisterProperty("Beds", typeof(ObservableCollection<Bed>));
        #endregion
    }
}
